<template>
  <div>
    <!--条件筛选-->
    <TopFilter :list="topFilterList" :cols="3" labelWidth="100" :collapse="boolean" @filterChange="changeHandle" @onCollapse="collapseHandle" @resetChange="resetChange"></TopFilter>
    <!--操作 -->
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <!-- 列筛选-->
    <FilterTable
      ref="table"
      columnsRef="lhmQueryEstimateEntrust"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :isSelectColumn="isSelectColumn"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChangeHandle"
      :onSyncTableData="tableAllData"
    >
      <template slot="controls" slot-scope="props"> </template>
    </FilterTable>
    <BasePrint ref="print" :data="printList" template="serviceAdviserAchievement" />
    <BaseDialog
      :visible.sync="visible6"
      title="客户"
      :closable="true"
      :destroyOnCloseSaleSingle="true"
      :maskClosable="true"
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <SelectKU @cancelManager6="cancelDialogManager6" @confirmManager="confirmDialogManager6" />
    </BaseDialog>
    <BaseDialog
      :visible.sync="visible7"
      title="车型"
      :closable="true"
      :destroyOnCloseSaleSingle="true"
      :maskClosable="true"
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <SelectCX @cancelManager7="cancelDialogManager7" @confirmManager="confirmDialogManager7" />
    </BaseDialog>
    <!-- 查询明细 -->
    <Drawer :visible.sync="labour" title="明细" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <labourModel :list="selectData" @closeDialog="closeDialog"></labourModel>
    </Drawer>
    <!-- printCMZ() {
      this.$refs.print.EXCUTE_PRINT();
    }, -->
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { checkList } from '@/api/repair/queryStatistics/queryEstimateEntrust';
import { getQueryEstimateEntrust } from '@/api/repair/queryStatistics/queryAccounts';
import { getUserListSelect } from '@/api/report/repair/repairreport';
import { searchRoleByCode } from '@/api/common/empSelect/index';
import dictCode from '@/utils/dictCode';
// 车型
import { getModel } from '@/api/customerRepair/customerCare/insuranceDueRemind/index';
import labourModel from '@/pages/repair/queryStatistics/queryEstimateEntrust/labourModel';
import SelectCX from './selectCX';
import SelectKU from './selectKU';
import ServiceAdvisor from './serviceAdvisor';
// 二手车置换
export default {
  name: 'LHMQueryEstimateEntrust',
  components: {},
  components: {
    SelectCX,
    SelectKU,
    ServiceAdvisor,
    labourModel
  },
  mixins: [dictionary],
  data() {
    this.conf = { add: '新增', delete: '删除', edit: '编辑', show: '显示' };
    this.formData = null;
    this.selectData = {};
    return {
      printList:{},
      topFilterList: this.createTopFilterList(),
      fetchParams: {},
      visible: false,
      visible1: false,
      visible6: false,
      visible7: false,
      visible8: false,
      dialogTitle: '',
      boolean: true,
      isSelectColumn: false,
      fetchApi: getQueryEstimateEntrust,
      columns: this.createTableCheckColumns(),
      handleType: '',
      formData: {},
      tableData: [],
      labour: false,
      modelCode: null,
      ownerNo: null,
      ids: []
    };
  },
  mounted() {
    // 分页
    this.FilterTable = this.$refs.table.$refs.pageTable;
    this.initSelect();
    this.querySeries();
  },
  methods: {
    async initSelect() {
      // 服务顾问
      let testDrive = { role: dictCode.SERVICE_CONSULTANT };
      let res5 = (await searchRoleByCode(testDrive)).data.map(x => ({ value: x.userId + '', text: x.employeeName }));
      this.topFilterList.find(item => item.fieldName === 'SERVICE_ADVISOR').itemList = res5;
      this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').editItems = res5;
    },
    async querySeries() {
      const car = await getModel();
      this.columns.find(x => x.dataIndex === 'MODEL').editItems = car.data.map(x => ({ text: x.MODEL_NAME, value: x.MODEL_ID + '' }));
    },
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '估算委托书编号',
          fieldName: 'ESTIMATE_NO'
        },
        {
          type: 'INPUT',
          label: '客户',
          fieldName: 'OWNER_NAME',
          placeholder: '请选择...',
          unitRender: () => {
            return <el-button slot="append" icon="el-icon-search" onClick={this.openManager6}></el-button>;
          }
        },
        {
          type: 'SELECT',
          label: '维修状态',
          fieldName: 'RO_STATUS',
          itemList: this.createDictList('8112')
        },
        {
          type: 'INPUT',
          label: '底盘号',
          fieldName: 'VIN'
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'MODEL_NAME',
          placeholder: '请选择...',
          unitRender: () => {
            return <el-button slot="append" icon="el-icon-search" onClick={this.openManager7}></el-button>;
          }
        },
        {
          type: 'SELECT',
          label: '处理状态',
          fieldName: 'ESTIMATE_HANDLE_STATUS',
          itemList: this.createDictList('8113')
        },
        {
          type: 'RANGE_DATE',
          label: '估算日期',
          fieldName: 'beginDate|endDate',
          placeholder: '选择日期'
        },
        {
          type: 'SELECT',
          label: '服务顾问',
          fieldName: 'SERVICE_ADVISOR',
          initialValue: '',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'LICENSE'
        }
      ];
    },
    createTableCheckColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          fixed: 'left',
          minWidth: '100',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.repairLabour(props.row)}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '估算委托书编号',
          dataIndex: 'ESTIMATE_NO',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '是否作废',
          dataIndex: 'IS_DELETED',
          showOverflowTooltip: true,
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <span>{props.row.IS_DELETED == 1 ? '是':'否'}</span>;
          }
        },
        {
          title: '维修状态',
          dataIndex: 'RO_STATUS',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          filterItems: this.createDictList('8112'),
          editType: 'select',
          editItems: this.createDictList('8112')
        },
        {
          title: '估算日期',
          dataIndex: 'RO_CREATE_DATE',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker'
        },
        {
          title: '处理状态',
          dataIndex: 'ESTIMATE_HANDLE_STATUS',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          filterItems: this.createDictList('8113'),
          editType: 'select',
          editItems: this.createDictList('8113')
        },
        {
          title: '客户名称',
          dataIndex: 'OWNER_NAME',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '客户固定电话',
          dataIndex: 'PHONE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '底盘号',
          dataIndex: 'VIN',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '车牌号',
          dataIndex: 'LICENSE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '车型',
          dataIndex: 'MODEL',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          editType: 'select',
          editItems: []
        },
        {
          title: '服务顾问',
          dataIndex: 'SERVICE_ADVISOR',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          editType: 'select',
          editItems: []
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        }
      ];
    },
    repairLabour(row) {
      this.selectData = row;
      this.labour = true;
    },
    closeDialog() {
      this.labour = false;
    },
    selectData(val) {
      this.tableData = val;
    },
    tableAllData(val) {
      this.printList = val;
    },
    selectChangeHandle(val) {
      this.selectedRow = val;
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val, { modelCode: this.modelCode }, { ownerNo: this.ownerNo });
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    openManager6() {
      this.visible6 = true;
    },
    openManager7() {
      this.visible7 = true;
    },
    openManager8() {
      this.visible8 = true;
    },
    confirmDialogManager6(val) {
      this.topFilterList.forEach(x => {
        if (x.fieldName === 'OWNER_NAME') {
          x.initialValue = val[0].OWNER_NAME;
          this.ownerNo = val[0].OWNER_NO;
        }
      });
      this.cancelDialogManager6();
      this.topFilterList = [...this.topFilterList];
    },

    confirmDialogManager7(val) {
      this.topFilterList.forEach(x => {
        if (x.fieldName === 'MODEL_NAME') {
          console.log('车型', val);
          x.initialValue = val[0].MODEL_NAME;
          this.modelCode = val[0].MODEL_CODE;
        }
      });

      this.cancelDialogManager7();
      this.topFilterList = [...this.topFilterList];
    },
    cancelDialogManager6() {
      this.visible6 = false;
    },
    cancelDialogManager7() {
      this.visible7 = false;
    },
    cancelDialogManager8() {
      this.visible8 = false;
    },
    showHandler() {
      // 显示
      this.dialogTitle = `其他费用`;
      this.visible = true;
    },
    saveHandle() {
      this.$refs.print.EXCUTE_PRINT();
    },
    resetChange() {
      this.modelCode = null;
      this.ownerNo = null;
    },
    closeHandler(val, type) {
      // 关闭
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>
<style lang="less" scoped></style>
